package com.atguigu.lease.web.app.controller.leasaterm;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.entity.LeaseTerm;
import com.atguigu.lease.model.entity.RoomLeaseTerm;
import com.atguigu.lease.web.app.service.LeaseTermService;
import com.atguigu.lease.web.app.service.RoomLeaseTermService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/app/term/")
@Tag(name = "租期信息")
public class LeaseTermController {
    @Autowired
    private LeaseTermService leaseTermService;
    @Autowired
    private RoomLeaseTermService roomLeaseTermService;

    /**
 * 根据房间ID获取可选租期列表
 * 此接口用于通过房间ID查询相关的租期信息，以便用户选择合适的租期
 * 主要涉及根据房间ID筛选房间租期记录，然后获取这些记录关联的租期详细信息
 *
 * @param id 房间ID，用于查询与该房间相关的租期信息
 * @return 包含租期列表的响应结果
 */
@GetMapping("listByRoomId")
@Operation(summary = "根据房间id获取可选获取租期列表")
public Result<List<LeaseTerm>> list(@RequestParam Long id) {
    /*// 创建查询条件，筛选出与指定房间ID匹配的房间租期记录
    LambdaQueryWrapper<RoomLeaseTerm> roomLeaseTermLambdaQueryWrapper = new LambdaQueryWrapper<>();
    roomLeaseTermLambdaQueryWrapper.eq(RoomLeaseTerm::getRoomId, id);

    // 执行查询，获取房间租期记录列表
    List<RoomLeaseTerm> list = roomLeaseTermService.list();

    // 从房间租期记录中提取租期ID，准备查询具体的租期信息
    List<Long> LeaseTermId = list.stream().map(RoomLeaseTerm::getLeaseTermId).toList();

    // 根据提取的租期ID列表，查询并获取具体的租期信息列表
    List<LeaseTerm> leaseTermList = leaseTermService.listByIds(LeaseTermId);

    // 返回查询结果，包含可选租期列表*/
    List<LeaseTerm>leaseTermList = leaseTermService.customList(id);
    return Result.ok(leaseTermList);
}

}
